//
//  CookCollectionViewCell.m
//  LiangYa_BObject
//
//  Created by dllo on 15/11/1.
//  Copyright © 2015年 YuHao. All rights reserved.
//

#import "CookCollectionViewCell.h"
#import "TeachintTableViewCell.h"
#import "TeachingData.h"
@implementation CookCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.tabelView = [[UITableView alloc] initWithFrame:self.contentView.bounds style:UITableViewStylePlain];
        self.tabelView.delegate = self;
        self.tabelView.dataSource = self;
        self.tabelView.separatorStyle = NO;
        self.tabelView.backgroundColor = [UIColor clearColor];

        [self.contentView addSubview:self.tabelView];
        
        [self.tabelView registerClass:[TeachintTableViewCell class] forCellReuseIdentifier:@"cell"];
        
    }
    
    return self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TeachintTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    TeachingData *selecteData = [self.dataArray objectAtIndex:indexPath.row];
    [cell.myimageView sd_setImageWithURL:[NSURL URLWithString:selecteData.cover_image_url] placeholderImage:[UIImage imageNamed:@"baikejiaju.png"]];
    cell.myLabel.text = selecteData.title;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    TeachingData *selecteData = [self.dataArray objectAtIndex:indexPath.row];
    [self.tabelView deselectRowAtIndexPath:indexPath animated:NO];
    self.block(selecteData);
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return cellHeight / 3.5;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    _tabelView.frame = CGRectMake(0, 0, cellWidth, cellHeight - 154);
}

@end
